package com.introse.student;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class Saver {
	private ArrayList<String> textLines;
	private File saver;
	
	public Saver (String saveName) {
		saver = new File(saveName+".txt");
		textLines = new ArrayList<String>();
	}
	
	public Saver (String saveName, ArrayList<String> textLines) {
		saver = new File(saveName+".txt");
		this.textLines = textLines;
	}
	
	public void addTextLine(String line) {
		textLines.add(line);
	}
	
	public void saveToFile() {
		try {
			PrintWriter save = new PrintWriter(new FileWriter(saver));

			for (String line : textLines) {
				save.println(line);
			}
			
			save.close();
		} catch (IOException e) {
			System.out.println("Writer error.");
			e.printStackTrace();
		}
	}
}
